package lagou.work.model1;

import java.io.Serializable;
import java.util.Objects;

public class Student implements Serializable {

    /**
     * 学号
     */
    private Integer id;
    /**
     * 年龄
     */
    private Integer age;
    /**
     * 姓名
     */
    private String name;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) throws IdException {
        if (id < 0) {
            throw new IdException("您所输入的学号不合理，请重新输入");
        }
        this.id = id;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) throws AgeException {
        if (age < 0 || age > 150) {
            throw new AgeException("您所输入的年龄不合理，请重新输入");
        }
        this.age = age;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id.equals(student.id) &&
                age.equals(student.age) &&
                name.equals(student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, age, name);
    }

    @Override
    public String toString() {
        return "当前学生{" +
                "学号：" + id +
                ", 年龄：" + age +
                ", 名字：'" + name + '\'' +
                '}';
    }
}
